/* fmpsrp10.i - ITEM-SITE FROMULA STRUCTURE INCLUDE FILE                      */
/* Copyright 1986-2008 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* Revision: 1.11.2.1                                                          */
/*                                                                            */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 9.0               CREATED: 10/22/98       BY: *J30L* Raphael T.  */
/* REVISION: 9.0         LAST MODIFIED: 03/13/99       BY: *M0BD* Alfred Tan  */
/* REVISION: 9.1         LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1         LAST MODIFIED: 08/14/00  BY: *N0L0* Jacolyn Neder    */
/* Revision: 1.7      BY: Jean Miller           DATE: 04/25/02  ECO: *P06H*   */
/* Revision: 1.8  BY: Mercy Chittilapilly DATE: 10/24/02 ECO: *N1XZ* */
/* Revision: 1.10 BY: Paul Donnelly (SB)  DATE: 06/26/03 ECO: *Q00C* */
/* Revision: 1.11.2.1     BY: Nishit V             DATE: 02/04/04 ECO: *P1MH* */
/* Revision: 1.11.2.2.1.1 BY: Dipanshu/Pushpalatha DATE: 05/05/08 ECO: *KYA6* */
/* $Revision: 1.11.2.2.1.2 $    BY: Jason Zhang          DATE: 09/26/08 ECO: *KYA4* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*KYA6*/ {pxmaint.i}
/*KYA6*/ {pxphdef.i pprevxr}

/*KYA6*/ define variable ptRev  like ptrv_rev no-undo.
/*KYA6*/ define variable ptpRev like ptrv_rev no-undo.

PROCEDURE process_report:
   define query q_ps_mstr for ps_mstr.
   define input parameter comp like ps_comp no-undo.
   define input parameter level as integer no-undo.
   define input parameter new_parent like mfc_logical.
   define buffer ptmstr for pt_mstr.

   for first ptp_det
      fields(ptp_domain ptp_bom_code ptp_iss_pol ptp_part ptp_phantom ptp_site)
      where ptp_det.ptp_domain = global_domain
      and   ptp_part           = comp
      and   ptp_site           = site
      no-lock:
   end. /* FOR FIRST ptp_det */

   if available ptp_det
   and ptp_bom_code <> ""
   then
      comp = ptp_bom_code.
   else
      for first pt_mstr
        fields (pt_domain  pt_bom_code pt_desc1 pt_desc2 pt_iss_pol
                pt_part    pt_phantom  /*KYA6* pt_rev */  pt_um)
        where pt_mstr.pt_domain = global_domain
        and   pt_part           = comp
        no-lock:
      end. /* FOR FIRST pt_mstr */

   if sort_ref then
      open query q_ps_mstr for each ps_mstr use-index ps_parref
          where ps_mstr.ps_domain = global_domain and  ps_par = comp and
               ps_op >= op   and
               ps_op <= op1  and
               ps_ps_code <> "J" no-lock.
   else
      open query q_ps_mstr for each ps_mstr use-index ps_parcomp
          where ps_mstr.ps_domain = global_domain and  ps_par = comp and
               ps_op >= op   and
               ps_op <= op1  and
               ps_ps_code <> "J" no-lock.

   get first q_ps_mstr no-lock.

   if not available ps_mstr then return.

   repeat while available ps_mstr with frame det2 down:

      /*DETAIL FORM */
      form
         lvl
         ps_comp format "x(26)" column-label "Component Item!Alt Item"
         ps_ref
         batch_size
         ps_qty_per_b
         ps_qty_type
         um
         ps_op
         phantom
         ps_ps_code column-label "SC"
         iss_pol
         ps_start
         ps_end
         ps_scrp_pct
         ps_lt_off
      with down frame det2 width 132 no-attr-space no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame det2:handle).

      if new_parent = yes then do:

         if page-size - line-counter < 7 then page.
         if not first-time then do:
            if skpge then page.
            else down 1.
         end.
         first-time = no.

         for first ptp_det
            fields( ptp_domain ptp_bom_code ptp_iss_pol ptp_part
                    ptp_phantom  /*KYA6* ptp_rev */    ptp_site)
             where ptp_det.ptp_domain = global_domain and  ptp_part = comp
            and   ptp_site = site
            no-lock:

         end. /* FOR FIRST ptp_det */

         if available ptp_det then

         for first bom_mstr
            fields( bom_domain bom_batch bom_batch_um bom_desc bom_parent)
             where bom_mstr.bom_domain = global_domain and  bom_parent = if
             ptp_bom_code <> ""
                               then
                                  ptp_bom_code
                               else
                                  comp
            no-lock:

         end. /* FOR FIRST bom_mstr */

         else

            for first bom_mstr
            fields( bom_domain bom_batch bom_batch_um bom_desc bom_parent)
                where bom_mstr.bom_domain = global_domain and  bom_parent = if
                available pt_mstr
                                     and pt_bom_code <> ""
                                  then
                                     pt_bom_code
                                  else
                                     comp
               no-lock:

            end. /* FOR FIRST bom_mstr */

         if available bom_mstr then
            assign
               batch_size = bom_batch
               um = bom_batch_um.
         else
            um = if available pt_mstr
                 then
                    pt_um
                 else "".

/*KYA4*/ find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
/*KYA4*/                        and ptal_part             = parent
/*KYA4*/                        and ptal_active
/*KYA4*/                        no-lock no-error.

         display
            getTermLabel("PARENT",10) @ lvl
            parent          @ ps_comp
            batch_size      when (available bom_mstr and bom_batch <> 1)
            um
            phantom         @ phantom
            iss_pol.
         down with frame det2.

/*KYA4*/ if available ptal_mstr
/*KYA4*/ then do:
/*KYA4*/    display ptal_alt_part @ ps_comp.
/*KYA4*/    down with frame det2.
/*KYA4*/ end.

         if available pt_mstr and pt_desc1 <> "" then do:
            display "  " + pt_desc1 @ ps_comp.
            down with frame det2.
         end.

         if available pt_mstr and pt_desc2 > "" then do:
            display "  " + pt_desc2 @ ps_comp.
            down with frame det2.
         end.
/*KYA6*/    {pxgetph.i pprevxr}
         if available ptp_det then do:
/*KYA6*/    ptpRev = {pxfunct.i &FUNCTION='getValidItemRevision'
                                    &PROGRAM='pprevxr.p'
                                    &HANDLE=ph_pprevxr
                                    &PARAM= "input ptp_part,
                                             input ptp_site,
                                             input eff_date"}.
/*KYA6*            if ptp_rev <> "" then do: */
/*KYA6*/    if ptpRev <> "" then do:
               display
/*KYA6*        getTermLabel("REVISION",12) + ": " +  ptp_rev @ ps_comp. */
/*KYA6*/       getTermLabel("REVISION",12) + ": " +  ptpRev @ ps_comp.
               down with frame det2.
            end.
         end.
/*KYA6*     else if available pt_mstr and pt_rev <> "" then do:  */
/*KYA6*/   else if available pt_mstr then do:
/*KYA6*/      ptRev = {pxfunct.i &FUNCTION='getValidItemRevision'
                           &PROGRAM='pprevxr.p'
                           &HANDLE=ph_pprevxr
                           &PARAM= "input pt_part,
                                    input '',
                                    input eff_date"}.
/*KYA6*/      if ptRev <> "" then do:
            display
/*KYA6*        getTermLabel("REVISION",12) + ": " +  pt_rev @ ps_comp. */
/*KYA6*/      getTermLabel("REVISION",12) + ": " +  ptRev @ ps_comp.
            down with frame det2.
/*KYA6*/    end.
         end.
         if bom_code <> parent then do:
            display
               getTermLabel("BILL_OF_MATERIAL",3) + ": " + bom_code @ ps_comp.
            down with frame det2.
         end.
         new_parent = no.
      end.  /* if new_parent = yes */

      if eff_date = ? or (eff_date <> ? and
         (ps_start = ? or ps_start <= eff_date) and
         (ps_end = ? or eff_date <= ps_end))
      then do:

         assign
            um       = ""
            desc1    = getTermLabel("ITEM_NOT_IN_INVENTORY",24)
            iss_pol  = no
            phantom  = no
            bom_code = ps_comp.

         find ptmstr  where ptmstr.pt_domain = global_domain and
         ptmstr.pt_part = ps_comp
         no-lock no-error.
         if available ptmstr then do:
            assign
               um       = ptmstr.pt_um
               desc1    = ptmstr.pt_desc1
               iss_pol  = ptmstr.pt_iss_pol
               phantom  = ptmstr.pt_phantom
               bom_code = if ptmstr.pt_bom_code <> ""
                          then ptmstr.pt_bom_code
                          else ptmstr.pt_part.
         end.
         else do:
            find bom_mstr no-lock  where bom_mstr.bom_domain = global_domain
            and  bom_parent = ps_comp
               no-error.
            if available bom_mstr then
               assign
                  um       = bom_batch_um
                  desc1    = bom_desc
                  bom_code = bom_parent.
         end.

         find ptp_det no-lock  where ptp_det.ptp_domain = global_domain and
         ptp_part = ps_comp
            and ptp_site = site no-error.
         if available ptp_det then
            assign
               iss_pol  = ptp_iss_pol
               phantom  = ptp_phantom
               bom_code = if ptp_bom_code <> ""
                          then ptp_bom_code
                          else ptp_part.

/*KYA4*/    find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
/*KYA4*/                           and ptal_part             = ps_comp
/*KYA4*/                           and ptal_active
/*KYA4*/                           no-lock no-error.

         lvl = "........".
         lvl = substring(lvl,1,min (level - 1,9)) + string(level).
         if length(lvl) > 10 then
            lvl = substring(lvl,length (lvl) - 9,10).

         lines = 1.
         if ps_rmks > "" then lines = lines + 1.
/*KYA4*/ if available ptal_mstr
/*KYA4*/ then
/*KYA4*/    lines = lines + 1.
         if available ptmstr and ptmstr.pt_desc1 > ""
         then
            lines = lines + 1.
         if available ptmstr and ptmstr.pt_desc2 > ""
         then
            lines = lines + 1.
/*KYA6*       if available ptp_det and ptp_rev > ""  */
/*KYA6*/   /* ADD BEGINS */
           if available ptp_det then
           do:
             {pxgetph.i pprevxr}
              ptpRev = {pxfunct.i &FUNCTION='getValidItemRevision'
                                  &PROGRAM='pprevxr.p'
                                  &HANDLE=ph_pprevxr
                                  &PARAM= "input ptp_part,
                                           input ptp_site,
                                           input eff_date"}.

              if ptpRev > ""
/*KYA6*/   /* ADD ENDS */
         then
            lines = lines + 1.
         else
/*KYA6*  if available ptmstr and ptmstr.pt_rev > "" */
/*KYA6* ADD BEGINS*/
         {pxgetph.i pprevxr}
         if available ptmstr
         then do:
            ptRev = {pxfunct.i &FUNCTION='getValidItemRevision'
                               &PROGRAM='pprevxr.p'
                               &HANDLE=ph_pprevxr
                               &PARAM= "input ptmstr.pt_part,
                                        input '',
                                        input eff_date"}.
            if ptRev > ""
/*KYA6*  ADD ENDS*/
         then
            lines = lines + 1.
         end.

         if page-size - line-counter < lines then page.

         find bom_mstr no-lock  where bom_mstr.bom_domain = global_domain and
         bom_parent = ps_comp
            no-error.
         if available bom_mstr then batch_size = bom_batch.

         display
            lvl
            ps_comp
            ps_ref
            batch_size when (available bom_mstr and batch_size <> 1)
            ps_qty_per_b
            ps_qty_type
            um
            ps_op
            phantom
            ps_ps_code
            iss_pol
            ps_start
            ps_end
            ps_scrp_pct when (ps_scrp_pct <>0)
            ps_lt_off
         with frame det2.
         down with frame det2.

/*KYA4*/ if available ptal_mstr
/*KYA4*/ then do:
/*KYA4*/    display ptal_alt_part @ ps_comp.
/*KYA4*/    down with frame det2.
/*KYA4*/ end.

         if desc1 > "" then do:
            display "  " + desc1 @ ps_comp.
            down with frame det2.
         end.

         if available ptmstr and ptmstr.pt_desc2 > "" then do:
            display "  " + ptmstr.pt_desc2 @ ps_comp.
            down with frame det2.
         end.
/*KYA6*  if available ptp_det and ptp_rev <> "" then do:   */
/*KYA6*/ if available ptp_det and ptpRev <> "" then do:
            display
/*KYA6*        getTermLabel("REVISION",12) + ": " +  ptp_rev @ ps_comp.  */
/*KYA6*/        getTermLabel("REVISION",12) + ": " +  ptpRev @ ps_comp.
            down with frame det2.
/*KYA6*/    end.
         end.
/*KYA6*    else if available ptmstr and ptmstr.pt_rev <> "" then do:  */
/*KYA6*/    else if available ptmstr AND ptRev <> "" then do:
            display
/*KYA6*         getTermLabel("REVISION",12) + ": " +  ptmstr.pt_rev @ ps_comp.  */
/*KYA6*/        getTermLabel("REVISION",12) + ": " +  ptRev @ ps_comp.
            down with frame det2.
         end.
         if length(ps_rmks) <> 0 then do:
            display "  " + ps_rmks @  ps_comp.
            down with frame det2.
         end.
         if bom_code <> ps_comp then do:
            display
               getTermLabel("BILL_OF_MATERIAL",3) + ": " + bom_code @ ps_comp.
            down with frame det2.
         end.

         if level < maxlevel or maxlevel = 0 then do:
            run process_report
               (input ps_comp, input level + 1,input new_parent).
            get next q_ps_mstr no-lock.
         end.
         else do:
            get next q_ps_mstr no-lock.
         end.
      end.  /* End of Valid date */
      else do:
         get next q_ps_mstr no-lock.
      end.
      {mfrpchk.i}
   end.  /* End of Repeat loop */
   close query q_ps_mstr.
END PROCEDURE.
